<?php
  //all code for this project falls under the MIT license - http://www.opensource.org/licenses/mit-license

  include './lib/margins.php';
  include './lib/gen_table.php';

  function add_raster($small_grid=0)
  {
    global $pdf;
    $pdf->SetLineWidth(0.1);
    //Draw gray lines - if required
    if ($small_grid == 1)
    {
      $pdf->SetDrawColor(180,180,180);
      for($x=0;$x<=210;$x+=2)
      {
        $pdf->Line($x,0,$x,297);
      }

      for($y=0;$y<=290;$y+=2)
      {
        $pdf->Line(0,$y,210,$y);
      }
    }
  
    //Draw blue lines + text
    $pdf->SetDrawColor(0,0,255);
    $pdf->SetFont('Arial','',10);
    
    for($x=0;$x<=210;$x+=10)
    {
      $pdf->Line($x,0,$x,297);
      $pdf->Text($x+1,4,$x);
    }
    
    for($y=0;$y<=290;$y+=10)
    {
      $pdf->Line(0,$y,210,$y);
      $pdf->Text(1,$y+4,$y);
    }
    $pdf->Line(0,297,210,297);
  }
  
  function draw_margins($margins)
  {
    global $pdf;
    $pdf->SetDrawColor(255,0,0);
    

    foreach($margins as $x)
    {
      $pdf->Line($x,0,$x,297);
    }
  }
   
   
// ------------------------------------------------------------------------------------------------------------------------  
  function add_footer($pdf,$rev,$page)
  {
    $pdf->SetTextColor(255,0,255);
     
    $pdf->SetFont('Arial','',6);
    $pdf->Text(22,277,'S-W GENESIS MANUAL');
    $pdf->Text(22,280,'Rev. '.$rev);
     
    $pdf->SetFont('times','B',14);
    $pdf->Text(40,290,'CONFIDENTIAL');
    $pdf->Text(90,290,'# 106');
    $pdf->Text(120,290,'PROPERTY OF SEGA');
     
    $pdf->Text(185,280,$page);
     
    //add_raster($pdf);
  }
   
// ------------------------------------------------------------------------------------------------------------------------  
  function toc_entry($pdf,$level,$y,$number,$caption,$page_nr)
  {
    switch($level)
    {
      default:
      case 0:
        $number_offset  = 30;
        $caption_offset = 44;
        break;
      case 1:
        $number_offset  = 44;
        $caption_offset = 55;
        break;
      case 2:
        $number_offset  = 55;
        $caption_offset = 68;
        break;
    }
     
    $pdf->Text($number_offset ,$y,$number);
    $pdf->Text($caption_offset,$y,$caption);
     
    if(!($page_nr == '-'))
    {
      //draw dots
      toc_draw_dots($pdf,$y,$caption_offset + $pdf->GetStringWidth($caption) + 2,184 - $pdf->GetStringWidth($page_nr) - 2); 
    
      //Align Right
      $pdf->Text(184 - $pdf->GetStringWidth($page_nr),$y,$page_nr);
    }
  }
   
// ------------------------------------------------------------------------------------------------------------------------  
  function toc_draw_dots($pdf,$y,$start,$end)
  {
    $pdf->SetDrawColor(0,0,0);

    $pdf->Line($start,$y-1.5,$end,$y-1.5);
    
    
    
  }
  
// ------------------------------------------------------------------------------------------------------------------------  
  
  function add_reserved_page($name,$bookmark_level_start=0,$bookmark_level_end=0)
  {
    global $pdf;
    $pdf->AddPage();

    $pdf->SetFont('arial','',30);
    $pdf->CenterText(0,50,'Page reserved for');

    $pdf->SetFont('arial','',80);
    $pdf->CenterText(0,100,$name);
    
    
    $pdf->SetFont('arial','B',200);
    $pdf->CenterText(0,200,$pdf->PageNo());
    
    
    if ($bookmark_level_end == 0) {$bookmark_level_end = $bookmark_level_start;}
    for($bml = $bookmark_level_start;$bml < $bookmark_level_end;$bml++)
    {
      $pdf->Bookmark('Reserved '.$bml.': Page '.$pdf->PageNo(),$bml);
    }
  }
 



  
?>
